package top.aicey.ai.sparring.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import top.aicey.ai.sparring.common.holder.SparringContext;
import top.aicey.ai.sparring.dto.event.GenerateReportEvent;
import top.aicey.ai.sparring.dto.event.ReportCompletedEvent;

/**
 * 事件发布者
 * @author admin
 */
@Component
public class ReportEventPublisher {

    @Autowired
    private ApplicationContext publisher;

    @Autowired
    private ReportProcessorExecutor reportProcessorExecutor;

    public void generateReport(SparringContext context){
        GenerateReportEvent event = new GenerateReportEvent(context.getModuleId(),context.getSceneId(),context.getInstanceId(),System.currentTimeMillis());

        // 生成报告
        reportProcessorExecutor.execute(event);
    }

    public void reportCompleted(String moduleId,Long sceneId,String instanceId){
        ReportCompletedEvent event = new ReportCompletedEvent(moduleId,sceneId,instanceId,System.currentTimeMillis());
        publisher.publishEvent(event);
    }

}
